home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TEGL6B.ARJ
/
TUTOR.COM
/
MENUS.TXT
< prev
next >
Wrap
Text File
|
1991-08-16
|
11KB
|
358 lines
MENUS
-------------------------------------------------------------------
The TEGL WINDOWS TOOLKIT II provides an extensive number of menu
functions. You can create bar menus and pull-down (or up) menus.
The basic item in a TEGL menu is the Option Menu. These are accessed
through a pointer, an OptionMPtr.
Creating a bar menu require a few steps. First we have to create
some option menus to attach to the bar menu. To do this use the function
CreateOptionMenu. It is declared as follows:
Function CreateOptionMenu(FontType: Pointer): OptionMPtr;
FontType is the font to use when displaying the menu selections. The
OptionMPtr that is returned is used to add selections to the option
menu and is finally attached to a bar menu (or mouse click area).
After the option menu has been created us DefineOptions to add selections
to the menu.
Procedure DefineOptions(VAR om; OptionMPtr; EntryStr : String;
Active : Boolean; Event: CallProc);
The first parameter, om, is the optionmptr that must have been created
with DefineOptions. EntryStr is the text that will be displayed for the
menu selection. Active sets whether the menu item can be selected, if
TRUE then it can be selected, when FALSE it cannot and will appear in
a lighter shade than the other menu selections. Event is the event-handler
that will be called when the menu selection is clicked on.
The '-' (hypen) is used to place a separator line between options, it will
appear as continuous line. When adding a separator the Active parameter
should alway be FALSE and the Event should be NilUnitProc which is a
place holder event-handler that just returns.
Note that menu selections (either bar or option menu) can have the tilde
character '~' placed around one of the characters in the text for the menu
selection. When this item is displayed the character will be underscored
and the corresponding key will be trapped for.
The next step is create a bar menu that the option menu('s) can be attached
to. To do this we use CreateBarMenu.
Procedure CreateBarMenu(x, y, length : Word);
x, y is the postion (in absolute screen coordinates) where the bar menu is
to be placed. Length is the length of the menu in pixels.
The font that is used to display the bar menu is the current font, if you
want to use a specific font use SetTeglFont before calling CreateBarMenu.
Hint: A bar menu is really just a long narrow frame, and like any frame
you change certain characteristics. Sometimes it might be useful to save
the StackPtr right after creating a bar menu.
When the bar menu has been created the option menus are attaced to it using
OutBarOption.
Procedure OutBarOption(EntryStr: String; om: OptionMPtr);
The EntryStr is the bar menu selection and om is the option menu that will
appear when the selection is made. The option menu will appear as a drop
down or drop up menu depending on where the bar menu is located.
Here is a small but complete program example of a bar menu with just
one selection. The one selection is an option menu with the entries:
'File' which does nothing, '-' which gives a separator line (for
appearance sake, and 'Exit' which will end the program.
Note: NilUnitProc is an event-handler which does nothing. It can be used
as place holder when you are creating the menu interface of program but
haven't completed the guts, and it is also used where an event parameter
(even one that is never called) is required.
BEGINFILE> menu1.pas
{-- menu1.pas }
{$F+}
USES
fastgrph, teglfont, tgraph, teglunit, teglmain, teglmenu;
function ExitOption(ifs : ImageStkPtr; Ms: MsClickPtr): Word;
BEGIN
Halt;
END;
VAR OmFile : OptionMPtr;
BEGIN
easytegl;
easyout;
OmFile := CreateOptionMenu(@f8x12bol);
DefineOptions(OmFile,' ~O~pen ',true,NilUnitProc);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptions(OmFile,' E~x~it ',true,ExitOption);
SetTeglFont(@f8x12bol);
CreateBarMenu(0,0,getmaxx);
OutBarOption(' ~F~ile ',OmFile);
TeglSupervisor;
END.
ENDFILE>
We can nest menus arbitrarily deep. To do this we use
DefineOptionsSub(OM: OptionMPtr; EntryStr: String; Active: Boolean;
OM2: OptionMPtr);
This simply attaches an option menu selection that is another option
menu as opposed to an event-handler. As you can see the last parameter
is an OptionMPtr.
This example adds two levels of menus, they don't do anything (that's
up to you) but it illustrates the use.
BEGINFILE> menu2.pas
{-- menu2.pas }
{$F+}
USES
fastgrph, teglfont, tgraph, teglunit, teglmain, teglmenu;
function ExitOption(ifs : ImageStkPtr; Ms: MsClickPtr): Word;
BEGIN
Halt;
END;
VAR
menufont : pointer; {-- by setting the font into a pointer we can }
{-- more easily change our selection of the font}
{-- to use. }
OmFile : OptionMPtr;
OMFile2 : OptionMPtr;
OmFile3 : OptionMPtr;
BEGIN
easytegl;
easyout;
menufont := @f8x12bol;
OmFile3 := CreateOptionMenu(menufont);
DefineOptions(OmFile3,' ~T~o floppy ',true,NilUnitProc);
DefineOptions(OmFile3,' ~F~rom floppy ',true,NilUnitProc);
OmFile2 := CreateOptionMenu(menufont);
DefineOptions(OmFile2,' ~F~ormat ',FALSE,NilUnitProc);
DefineOptions(OmFile2,' ~D~elete ',FALSE,NilUnitProc);
DefineOptionsSub(OmFile2,' ~C~opy ',true,OmFile3);
OmFile := CreateOptionMenu(menufont);
DefineOptions(OmFile,' ~O~pen ',true,NilUnitProc);
DefineOptionsSub(OmFile,' ~D~os functions ',true,OmFile2);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptions(OmFile,' E~x~it ',true,ExitOption);
SetTeglFont(menufont);
CreateBarMenu(0,0,getmaxx);
OutBarOption(' ~F~ile ',OmFile);
TeglSupervisor;
END.
ENDFILE>
Some people really get carried away when it comes to making menus,
generally we don't recommend really long menus and try to keep them
under several hundred items.
This example just shows what happens when an excessive number of menu
selections is added to an option menu.
BEGINFILE> menu3.pas
{-- menu3.pas }
{$F+}
USES
fastgrph, teglfont, tgraph, teglunit, teglmain, teglmenu;
function itos(i: Integer): String;
var s :string;
BEGIN
str(i,s);
itos := s + ' ';
END;
function ExitOption(ifs : ImageStkPtr; Ms: MsClickPtr): Word;
BEGIN
Halt;
END;
VAR OmFile : OptionMPtr;
OmOpen : OptionMPtr;
i : Integer;
BEGIN
easytegl;
easyout;
OmOpen := CreateOptionMenu(@f8x8Bold);
for i := 1 to 50 do
DefineOptions(OmOpen,' file '+itos(i),random(2)=1,NilUnitProc);
OmFile := CreateOptionMenu(@f8x12bol);
DefineOptionsSub(OmFile,' ~O~pen ',true,OmOpen);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptions(OmFile,' E~x~it ',true,ExitOption);
SetTeglFont(@f8x12bol);
CreateBarMenu(0,0,getmaxx);
OutBarOption(' ~F~ile ',OmFile);
TeglSupervisor;
END.
ENDFILE>
A useful item to have in a menu is a check-marked item. These are usually
boolean flags to indicate some sort of preference. There is a special
option menu item for this:
DefineOptionsCheck(OM: OptionMPtr; EntryStr: String; Active: Boolean;
Event: CallProc; VAR ChkMark : Boolean);
The big distinction here is that we pass a variable to the routine so
that when it is selected the variable will be toggled. After the variable
is updated then the event-handler is called, presumably to do some
processing if required. Our example doesn't do this, but you probably
get the idea.
When the item is TRUE then a check mark is displayed next to it, when
FALSE no check mark.
BEGINFILE> menu4.pas
{-- menu4.pas }
{$F+}
USES
fastgrph, teglfont, tgraph, teglunit, teglmain, teglmenu;
function ExitOption(ifs : ImageStkPtr; Ms: MsClickPtr): Word;
BEGIN
Halt;
END;
VAR
menufont : pointer;
OmFile : OptionMPtr;
CONST
FullPath : Boolean = True;
BEGIN
easytegl;
easyout;
menufont := @f8x12bol;
OmFile := CreateOptionMenu(menufont);
DefineOptions(OmFile,' ~O~pen ',true,NilUnitProc);
DefineOptionsCheck(OmFile,' ~F~ull path ',true,nilunitproc,fullpath);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptions(OmFile,' E~x~it ',true,ExitOption);
SetTeglFont(menufont);
CreateBarMenu(0,0,getmaxx);
OutBarOption(' ~F~ile ',OmFile);
TeglSupervisor;
END.
ENDFILE>
Another useful kind of check mark is one where there can be a limited
number of choices but more than just a boolean toggle.
DefineOptionsRadio(OM : OptionMPtr; EntryStr: String; Active: Boolean;
Event: CallProc; EntryRadioValue: Word; VAR ChkVar: Word);
Here the distinction is ChkVar is a Word value, so you could have
a lot of choices but generally this kind of item is used for 2 to 5 or
perhaps a few more. Each item that uses the same ChkVar must have
a different EntryRadioValue. As with DefineOptionsCheck the event-handler
is called after the variable has been updated.
BEGINFILE> menu5.pas
{-- menu5.pas }
{$F+}
USES
fastgrph, teglfont, tgraph, teglunit, teglmain, teglmenu;
function ExitOption(ifs : ImageStkPtr; Ms: MsClickPtr): Word;
BEGIN
Halt;
END;
VAR
menufont : pointer;
OmFile : OptionMPtr;
CONST
SortOption : Word = 1;
BEGIN
easytegl;
easyout;
menufont := @f8x12bol;
OmFile := CreateOptionMenu(menufont);
DefineOptions(OmFile,' ~O~pen ',true,NilUnitProc);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptionsRadio(OmFile,' ~N~ame ',true,nilunitproc,1,SortOption);
DefineOptionsRadio(OmFile,' ~E~xtension ',true,nilunitproc,2,SortOption);
DefineOptionsRadio(OmFile,' ~D~ate ',true,nilunitproc,3,SortOption);
DefineOptionsRadio(OmFile,' N~o~ne ',true,nilunitproc,4,SortOption);
DefineOptions(OmFile,'-',false,nilunitproc);
DefineOptions(OmFile,' E~x~it ',true,ExitOption);
SetTeglFont(menufont);
CreateBarMenu(0,0,getmaxx);
OutBarOption(' ~F~ile ',OmFile);
TeglSupervisor;
END.
ENDFILE>
PREFERENCES
You can set a number of items to suit your needs or preferences
for menus.
SetHideSubMenu(OnOff: Boolean);
This sets whether the sub menus should be dropped before the resulting
event-handler has returned. The default is for the sub menus to remain
visible on the screen (FALSE). If set TRUE then the menus are hidden just
as soon as a selection is made.
SetOMDisplayNum(OM : OptionMPtr; Num: Word);
This sets the limit on how many menu items to display before an
option menu sprouts a slider bar. If you don't change it then the
menu can be the full size of the screen.
See the example program 'menudemo.pas' for a comprehensive look at
how a menu system can be set up.
------- END MENUS.TXT